home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: Q: how to create an Object without creating the whole object
- Date: Sat, 16 Mar 1996 21:15:34 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4ifb0a$5q0@news.halcyon.com>
- References: <31454EC9.167E@imacsg2.epfl.ch> <4i9eqo$dtu@uuneo.neosoft.com>
- NNTP-Posting-Host: blv-pm3-ip13.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Wmatthew@lan-aces.com (W. Matthews) wrote:
-
- >In article <31454EC9.167E@imacsg2.epfl.ch>, Niels Hilbrink <niels@imacsg2.epfl.ch> says:
- >>
- >>Hi,
- >>
- >>Oke the problem is this (maybe it's in a FAQ but couldn't find the faq
- >>so ...):
- >>
- >>Say you've got a class A which is composed of say 10 other class
- >>(inheritance multiple and single whatever). But if I create an object
- >>with new this class 'explodes' (all the member functions are created of
- >>all the parentclasses) so you want the initialize only those parent
- >>class you need say only class B.
- >>
- >>How do you do that ?
- >>
- >>something like:
- >>
- >> Aobj = (A*) new A::B()
- >>
- >>But this doen't work, can anybody tell me what will ?
- >>
- >>oh yeah this works of course :
- >> Bobj = new B;
- >>
- >> Aobj = (A*) Bobj;
- >>
- >>but I don't want that, I don't want first to have to create a B object
- >>and "attach" it to the A object
- >>
- >>Gr.
- >>Niels
- >>
- >>--
- >>
- >> The most overlooked advantage to owning a computer is
- >> that if they foul up there's no law against wacking
- >> them around a little.
- >>
- >>------------------------------------------------------------
- >>Koen D'Hondt Niels Hilbrink
- >>koen@dutlhs1.lr.tudelft.nl niels@dutlcc3.lr.tudelft.nl
- >>
- >>**** Ripley Software Development ****
- >>(finger niels@dutlcc3.lr.tudelft.nl for more information.)
- >>------------------------------------------------------------
- >Have you tried using a generic base class? Then, in class 'A'
- >call the base with the appropriate class conversions to get 'B'.
- ><Don't mind me, I may turn out to be rambling on this one.>
- >______________________________________________
- >|Wyatt Matthews: Tech Support Department |
- >|WMATTHEW@LAN-ACES.COM -Internet- |
- >|WMATTHEW.MHS@LAN-ACES -MHS- |
- >|LAN-ACES Tech Support (713)890-9786 |
- >|LAN-ACES BBS (713)890-9790 |
- >|LAN-ACES Fax (713)890-9731 |
- >|LAN-ACES Sales (713)890-9787 |
- >______________________________________________
-
- Sorry, it's all or nuthin. How's a compiler supposed to know what
- methods you'll want to use?
-
- Creating a B, playing on it, then 'attaching' it to A (i.e, tell A to
- use the B *) is all you're left with.
-
- --Norm
-
-